package demo1;

public class demo_03Thread {
    public static void main(String[] args) throws InterruptedException {
        //创建一个线程
        Thread thread =new Thread(()->{
            //线程任务
            for (int i = 0; i <5 ; i++) {
                System.out.println("thread线程正在运行.....");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }


        });
        //在启动线程之前查看一下线程对象的属性
        System.out.println(
                "线程启动之前查看属性"+"\n"+
                "thread的ID："+ thread.getId()+"\n"
                +"thread的Name："+thread.getName()+"\n"
                +"thread的State："+thread.getState()+"\n"
                +"thread的Priority："+thread.getPriority()+"\n"
                +"thread是否是后台线程："+thread.isDaemon()+"\n"
                +"thread对应的系统线程的是否存活："+thread.isAlive()+"\n"
                +"thread线程是否被中断："+thread.isInterrupted()+"\n"
        );
        //启动线程
        thread.start();
        //等待一下thread线程，保证子线程启动
        Thread.sleep(1000);
        //启动线程后查看属性
        System.out.println(
                "线程运行中查看属性"+"\n"+
                "thread的ID："+ thread.getId()+"\n"
                        +"thread的Name："+thread.getName()+"\n"
                        +"thread的State："+thread.getState()+"\n"
                        +"thread的Priority："+thread.getPriority()+"\n"
                        +"thread是否是后台线程："+thread.isDaemon()+"\n"
                        +"thread对应的系统线程的是否存活："+thread.isAlive()+"\n"
                        +"thread线程是否被中断："+thread.isInterrupted()+"\n"
        );
        //等待子线程结束后被销毁
        thread.join();
//        Thread.sleep(1000);
        //线程结束后查看线程属性
        System.out.println(
                "线程被销毁之后查看属性"+"\n"+
                "thread的ID："+ thread.getId()+"\n"
                        +"thread的Name："+thread.getName()+"\n"
                        +"thread的State："+thread.getState()+"\n"
                        +"thread的Priority："+thread.getPriority()+"\n"
                        +"thread是否是后台线程："+thread.isDaemon()+"\n"
                        +"thread对应的系统线程的是否存活："+thread.isAlive()+"\n"
                        +"thread线程是否被中断："+thread.isInterrupted()+"\n"
        );


    }
}
